package entitys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class SolicitudCompra implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 8733310680242889460L;
	private int idSolCom;
	private Cliente cliente;
	private List<ItemSolicitudCompra> items;
	private Remito remito;
	private Factura factura;

	public SolicitudCompra() {
		items = new ArrayList<ItemSolicitudCompra>();
	}

	@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "idSolCom", nullable = false)
	public int getIdSolCom() {
		return idSolCom;
	}


	public void setIdSolCom(int idSolCom) {
		this.idSolCom = idSolCom;
	}

	@ManyToOne
	@LazyCollection(LazyCollectionOption.FALSE)
	public Cliente getCliente() {
		return cliente;
	}


	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

    @OneToMany(cascade=CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    @JoinColumn(name = "idSolCom")
	public List<ItemSolicitudCompra> getItems() {
		return items;
	}


	public void setItems(List<ItemSolicitudCompra> items) {
		this.items = items;
	}

	@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
	public Remito getRemito() {
		return remito;
	}

	public void setRemito(Remito remito) {
		this.remito = remito;
	}

	@OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
	public Factura getFactura() {
		return factura;
	}

	public void setFactura(Factura factura) {
		this.factura = factura;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idSolCom;
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SolicitudCompra other = (SolicitudCompra) obj;
		if (idSolCom != other.idSolCom)
			return false;
		return true;
	}


	public void addItem(ItemSolicitudCompra oItem) {
		items.add(oItem);
	}
	
}